﻿//---------------------------------------------------AjaxHelper------------------------------------------------

var AjaxProxyUrl = new String("../ajax.aspx");

var AjaxHelper =
{
    Updater: function (ajaxTemplate, output, params, onComplete) {
        if (typeof output == 'string') {
            output = $(output);
        }

        var FormatContent = function (str) {
            var content = new String(str);
            var prefix = new String("<!--AjaxContent-->");
            content = content.substring(content.indexOf(prefix, 0) + prefix.length, content.length - 9);
            return content;
        }
        this.result = "1";
        var myrequest = new Ajax.Request(AjaxProxyUrl,
		{ onComplete: function (transport) {
		    if (output != null)
		    { output.innerHTML = FormatContent(transport.responseText); }
		    if (onComplete != null)
		    { onComplete(FormatContent(transport.responseText)) }

		    if ($("loading_mask") != undefined && $("loading") != undefined) {
		        $("loading_mask").style.display = "none";
		        $("loading").style.display = "none";
		    }
		}, parameters: params + '&AjaxTemplate=' + ajaxTemplate
		});

        var requeststate = myrequest.transport.readyState;
        if (requeststate != 4) {
            if ($("loading_mask") != undefined && $("loading") != undefined) {
                $("loading_mask").style.display = "block";
                $("loading").style.display = "block";
            }
        }

        return this.result;
    },


    SerializeForm: function (form) {
        return Form.serialize(form);
    }

}

function loading() {
    var body = document.getElementsByTagName("body")[0];

    var bodySize = [];
    bodySize[0] = (document.documentElement.scrollWidth > document.documentElement.clientWidth) ? document.documentElement.scrollWidth : document.documentElement.clientWidth; //如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
    bodySize[1] = (document.documentElement.scrollHeight > document.documentElement.clientHeight) ? document.documentElement.scrollHeight : document.documentElement.clientHeight; //如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.style.top = "50%";
    div.style.left = "50%";
    div.style.margin = "-50px 0 0 -100px";
    div.style.padding = "15px";
    div.style.border = "0px solid #B2D0F7";
    div.style.color = "#003366";
    div.style.font = "bold 14px verdana,tahoma,helvetica";
    div.style.zIndex = '10002';
    div.style.textAlign = "center";
    div.innerHTML = "<img src='../images/loading.gif'/>";
    div.id = "loading";
    body.appendChild(div);
    div.style.display = "none";

    var divmask = document.createElement('div');
    divmask.style.position = 'absolute';
    divmask.style.width = bodySize[0] + "px";
    divmask.style.height = bodySize[1] + "px";
    divmask.style.top = "0px";
    divmask.style.left = "0px";
    divmask.style.zIndex = '10001';
    divmask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60,finishOpacity=100,style=0)';
    divmask.style.opacity = 0.9;
    divmask.style.background = "#ffffff";
    divmask.id = "loading_mask";
    body.appendChild(divmask);
    divmask.style.display = "none";
}